import { defineStore } from "pinia";

export interface ConfigStoreModel {
    ap: {
        name: string;
        pwd: string | null;
    };
    name: string;
    secret_id: string;
    secret_key: string;
    server_api: string;
    weather: {
        city: string;
        loc: string;
    };
    wifi: {
        name: string;
        pwd: string;
    };
    version: string;
    ip: string[];
    uname: {
        machine: string;
        nodename: string;
        release: string;
        sysname: string;
        version: string;
    };
    device_ip?: string;
    birthday_date: string;
    led: {
        status: boolean;
        rgb: number[];
    };
    mirror_flip: boolean;
}

export const useConfigStore = defineStore("config", {
    state: (): ConfigStoreModel => ({
        ap: {
            name: "",
            pwd: null
        },
        name: "",
        secret_id: "",
        secret_key: "",
        server_api: "",
        weather: {
            city: "",
            loc: ""
        },
        wifi: {
            name: "",
            pwd: ""
        },
        version: "",
        ip: [],
        uname: {
            machine: "",
            nodename: "",
            release: "",
            sysname: "",
            version: ""
        },
        device_ip: undefined,
        birthday_date: "",
        led: {
            status: false,
            rgb: [0, 0, 0]
        },
        mirror_flip: false
    }),
    persist: true,
    getters: {},

    actions: {
        updateDeviceConfig(data: object): void {
            this.$patch(data);
        }
    }
});
